<template>
	<view class="page">
		<view class="container">
		    <view class="separate"></view>
		    <view class="name-view input">
		        <view class='title'>收货人：</view>
		        <input class="name" placeholder="请输入姓名" v-model="name"/>
		    </view>
		    <view class="phone-view input">
		        <view>手机号：</view>
		        <input class="phone" type="number"  placeholder="请输入手机号码" v-model="phone"/>
		    </view>
		   
		   <view class="phone-view input">
		        <view class='title'>所在学校：</view>
		        <input class="school" type="text"  placeholder="如安徽国防科技职业学院" v-model="school"/>
		    </view>
		
		    <view class="phone-view input">
		        <view class='title'>所在楼栋：</view>
		        <input class="detail" type="text"  placeholder="如1栋301" v-model="detail"/>
		    </view>
		    <button class="save-address" @tap="saveAddress">保存收货地址</button>
		
		</view>
	</view>
</template>

<script>
	import tools from '@/static/utils/tools.js'
	var userInfo = ''
	export default {
		data() {
			return {
				name:'',
				phone:'',
				school:'',
				detail:'',
			}
		},
		methods: {
			saveAddress: function(e) {
			    var that = this;
			    var phone = that.phone;
			    var name = that.name;
			    var school = that.school;
			    var detail = that.detail;
				
				userInfo = uni.getStorageSync('userInfo');
				var user_id = 4829;//userInfo.id
				
			    if (name == null || name == '') {
			      nui.showToast({
			        title: '收货人不能为空',
			        duration: 1000
			      });
			      return false;
			    }
			    if (phone == null || phone == '') {
			        nui.showToast({
			            title: '手机号不能为空',
			            duration: 1000
			        });
			        return false;
			    }
			   
			    if (school == null || school == '') {
			      nui.showToast({
			        title: '学校不能为空',
			        duration: 1000
			      });
			      return false;
			    }
			    if (detail == null || detail == '') {
			        nui.showToast({
			            title: '楼栋不能为空',
			            duration: 1000
			        });
			        return false;
			    }
			    if (!(/^[0-9]*$/.test(phone))) {
			        wx.showToast({
			            title: '手机号必须为数字',
			            duration: 1000
			        });
			        return false;
			    }
			   
			    var myData = {
			        user_id: user_id,
			        call_name: name,
			        phone: phone,
			        school: school,
			        detail: detail,
			    };
			
			   tools.httpClient('get','index.php?c=shop&a=insertAddress',myData,(res) => {
					console.log(res,1122233)
					if(res.errorCode == 0){
						uni.showToast({
						    title: '保存成功',
						    icon: 'success',
						    duration: 1500,
						});
						setTimeout(function() {
						    uni.navigateBack();
						}, 1500)
					}
			   	
			   });
			
			
			},
		}
	}
</script>

<style>
.page {
    background-color: #f0f0f0; 
    -webkit-text-size-adjust: 100%;
    font-family: "微软雅黑";
}
.container {
  padding: 0;
  background-color: #fff;
}
.input{
    display: flex;
    align-items: center;
    width: 100%;
    padding: 20rpx 0;
    padding-left: 30rpx;
    border-bottom: 1px solid #e4e4e4;
}
.input .title{
  display: flex;
  flex-wrap: nowrap
}
.container .address-view {
  position: relative;
  height: 170rpx;
  line-height: 2;
}

.container .address-view input {
  border: 1px solid #ccc;
  padding: 7rpx 0;
  border-radius: 6rpx;
  padding-left: 5rpx;
}

.container .address-view .address {
  width: 500rpx;
  position: absolute;
  top: 20rpx;
  left: 150rpx;
}

.container .address-view .detail {
  width: 500rpx;
  position: absolute;
  top: 100rpx;
  left: 150rpx;
}

.container .save-address {
  width: 90%;
  color: #fff;
  background-color: #ff0000;
  margin-top: 100rpx;
  height: 80rpx;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  border-radius: 6rpx;
}

/* 选择器 */
.citypickers{
  position: fixed;
  height: 100%;
  width: 100%;
  min-height: 100%;
  background-color: red;
}

.citypicker{
  
}
.citybody {
  position: fixed;
  bottom: 0px;
  background: #fff;
}
.citybody view {
	text-align: center;
}

.cityheader {
	box-sizing: border-box;
	position: absolute;
	top:0px;
	width: 100%;
	z-index: 4;
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	padding: 10rpx;
	font-size: 32rpx;
}

</style>
